﻿using _0016.Gonggong.Models;
using _0016.Tuozhanfangfa;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _0016.ViewModels
{
    public class MainViewModel:BindableBase
    {
        public MainViewModel(IRegionManager regionManager)
        {
            Caidans = new ObservableCollection<Caidans>();
            Createcaidan();
            NavigateCommand=new DelegateCommand<Caidans>(Navigate);
            GoBackCommand = new DelegateCommand(() =>
            {
                if (journal != null && journal.CanGoBack)
                {
                    journal.GoBack();
                }
            });
            GoForwardCommand = new DelegateCommand(() =>
            {
                if (journal!=null&&journal.CanGoForward)
                {
                    journal.GoForward();
                }
            });
            this.regionManager = regionManager;
        }

        private void Navigate(Caidans obj)
        {
            if (obj==null||string.IsNullOrWhiteSpace(obj.Namespace))
            {
                return;
            }
            regionManager.Regions[PrismManager.MainViewRegionName].RequestNavigate(obj.Namespace,back=>
            {
                journal = back.Context.NavigationService.Journal;
            });
           
        }
        public DelegateCommand GoForwardCommand { get; private set; }
        public DelegateCommand GoBackCommand{get;private set;}
        public DelegateCommand<Caidans> NavigateCommand
        {
            get;
            private set;        
        }

        private IRegionNavigationJournal journal;
        private readonly IRegionManager regionManager;
        private ObservableCollection<Caidans> _caidans;

        public ObservableCollection<Caidans> Caidans
        {
            get { return _caidans; }
            set { _caidans = value; RaisePropertyChanged(); }
        }
        void Createcaidan()
        {
            Caidans.Add(new Caidans() { Tubiao = "Home", Title = "首页",  Namespace = "IndexView" });
            Caidans.Add(new Caidans() { Tubiao = "NotebookOutline", Title = "待办事项",  Namespace = "ToDoView" });
            Caidans.Add(new Caidans() { Tubiao = "NotebookPlus", Title = "备忘录",  Namespace = "MemoView" });
            Caidans.Add(new Caidans() { Tubiao = "Cog", Title = "设置", Namespace = "SettingsView" });
        }
    }
}
